package com.bjc.nio.c1;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * @program: nettypro
 * @description: 拷贝多级目录
 * @author: bjc
 * @create: 2021-09-16 21:12
 */
public class TestFileCopy {

    public static void main(String[] args) throws IOException {
        String source = "D:\\iotest_delete";
        String target = "D:\\iotest_delete_test";

        Files.walk(Paths.get(source)).forEach(path -> {
            try {
                String targetName = path.toString().replace(source, target);
                //是目录
                if (Files.isDirectory(path)){
                    Files.createDirectory(Paths.get(targetName));
                //是文件
                }else if (Files.isRegularFile(path)){
                    Files.copy(path,Paths.get(targetName));
                }
            }catch (IOException e){
                e.printStackTrace();
            }
        });
    }
}
